package com.tm.exception.utils;


public class Result<T>{
    private int code;
    private String msg;
    private T data;

    public Result() {
    }

    public Result(ResultCode ResultCode){
        this.code = ResultCode.getCode();
        this.msg = ResultCode.getMessage();
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public Object getData() {
        return data;
    }

    public Result(ResultCode ResultCode, T data){
        this.code = ResultCode.getCode();
        this.msg = ResultCode.getMessage();
        this.data = data;
    }

    public static Result success(){
        return new Result(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(),null);
    }
    public static Result success(Object data){
        return new Result(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }
    public static Result suceess(ResultCode resultCode){
        return new Result(resultCode.getCode(), resultCode.getMessage(), null);
    }
    public static Result success(ResultCode resultCode,Object data){
        return new Result(resultCode.getCode(),resultCode.getMessage(),data);
    }

    public static Result error(){

        return new Result(ResultCode.ERROR);
    }

    public static Result error(ResultCode ResultCode){

        return new Result(ResultCode);
    }
    public static Result error(int code, String msg){

        return new Result(code,msg,null);
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

}
